home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 3794 / 3794.xpi / chrome / content / notifier.js < prev    next >
Text File  |  2009-08-13  |  3KB  |  68 lines

  1. /**
  2.  *
  3.  * The source code included in this file is licensed to you by Facebook under
  4.  * the Apache License, Version 2.0.  Accordingly, the following notice
  5.  * applies to the source code included in this file:
  6.  *
  7.  * Copyright ┬⌐ 2009 Facebook, Inc.
  8.  *
  9.  * Licensed under the Apache License, Version 2.0 (the "License"); you may
  10.  * not use this file except in compliance with the License. You may obtain
  11.  * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
  12.  *
  13.  * Unless required by applicable law or agreed to in writing, software
  14.  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  15.  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  16.  * License for the specific language governing permissions and limitations
  17.  * under the License.
  18.  *
  19.  */
  20.  
  21.  
  22. var _src   = window.arguments[0],
  23.     _label = window.arguments[1],
  24.     _url   = window.arguments[2],
  25.     _count = window.arguments[3];
  26. var _winService = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator),
  27.     _prefService = Cc['@mozilla.org/preferences-service;1'].getService(Ci.nsIPrefBranch);
  28.  
  29. function NotifierLoad() {
  30.     debug('NotifierLoad', _label, _url);
  31.     document.getElementById('pic').setAttribute('src', _src );
  32.     document.getElementById('label').appendChild(document.createTextNode(_label));
  33.     window.setTimeout('window.close();', 10000);
  34.     window.addEventListener('mouseup', NotifierClick, false);
  35. }
  36. function NotifierClick() {
  37.     debug('NotifierClick', _label, _url );
  38.     window.close();
  39.  
  40.     if (_url) { // open
  41.         var win = _winService.getMostRecentWindow( "navigator:browser" );
  42.         var browser = win ? win.getBrowser() : null;
  43.         if( browser
  44.           && 2 != _prefService.getIntPref('browser.link.open_newwindow') )
  45.           // 1 => current Firefox window;
  46.           // 2 => new window;
  47.           // 3 => a new tab in the current window;
  48.         { // open in a focused tab
  49.           var tab = browser.addTab(_url);
  50.           browser.selectedTab = tab;
  51.           win.content.focus();
  52.         }
  53.         else {
  54.           window.open(_url);
  55.         }
  56.     }
  57. }
  58. function NotifierUnload() {
  59.     debug('NotifierUnload', _label);
  60.     if( _count )
  61.       _count.value--;
  62. }
  63. // For some reason window.onload doesn't seem to get triggered if we are
  64. // opening mulitple windows at a time.  Need to use DOMContentLoaded instead.
  65. document.addEventListener("DOMContentLoaded", NotifierLoad, false);
  66. window.addEventListener('unload', NotifierUnload, false);
  67. debug('loaded notifier.js', window.arguments.length);
  68.